#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;

using Microsoft.Xna.Framework;
using JigLibX.Collision;
#endregion

namespace JigLibX.Physics
{

    #region BasicCollisionFunctor

    public class BasicCollisionFunctor : CollisionFunctor
    {

        private List<CollisionInfo> colls;

        public BasicCollisionFunctor(List<CollisionInfo> colls)
        {
            this.colls = colls;
        }

        public override void CollisionNotify(CollDetectInfo collDetectInfo, Vector3 dirToBody0, List<CollPointInfo> pointInfos)
        {
            CollisionInfo info;

            // if more than one point, add another that is in the middle - collision

            if ((collDetectInfo.Skin0 != null) && (collDetectInfo.Skin0.Owner != null))
            {
                info = CollisionInfo.GetCollisionInfo(collDetectInfo, dirToBody0, pointInfos);
                colls.Add(info);
                collDetectInfo.Skin0.Collisions.Add(info);

                if ((collDetectInfo.Skin1 != null) && (collDetectInfo.Skin1.Owner != null))
                    collDetectInfo.Skin1.Collisions.Add(info);
            }
            else if ((collDetectInfo.Skin1 != null) && (collDetectInfo.Skin1.Owner != null))
            {
                info = CollisionInfo.GetCollisionInfo(collDetectInfo, -dirToBody0, pointInfos);
                colls.Add(info);
                collDetectInfo.Skin1.Collisions.Add(info);
                if ((collDetectInfo.Skin0 != null) && (collDetectInfo.Skin0.Owner != null))
                    collDetectInfo.Skin0.Collisions.Add(info);
            }
            else
                throw new JigLibXException("Collision detected with both skin bodies null.");
        }
    }

    #endregion

    #region FrozenCollisionPredicate

    public class FrozenCollisionPredicate : CollisionSkinPredicate2
    {

        private Body body;

        public FrozenCollisionPredicate(Body body)
        {
            this.body = body;
        }

        public override bool ConsiderSkinPair(CollisionSkin skin0, CollisionSkin skin1)
        {
            if ((skin0.Owner != null) && (skin0.Owner != body))
                if (!skin0.Owner.IsActive) return true;

            if ((skin1.Owner != null) && (skin1.Owner != body))
                if (!skin1.Owner.IsActive) return true;

            return false;
        }
    }
    #endregion

}
